import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author Megan Beebe
 *
 * This private inner class is the main screen of the game. It holds player 
 * information and what is currently going on in the game.
 *
 */

@SuppressWarnings("serial")
public class MainScreen extends JPanel {
	/**
	 * Constructor for MainScreen
	 */
	public MainScreen() {
		this.setLayout(new BorderLayout());
		addPanels();
	}

	/**
	 * adds all panels to the mainScreen panel, including the panel for player information and a panel
	 * for the main game screen.
	 *
	 */

	private void addPanels() {
		JPanel begin = new JPanel();
		GameModel.getInstance().setLabel("Main Screen");
		begin.add(GameModel.getInstance().getLabel());
		this.add(begin, BorderLayout.NORTH);
		JPanel mapPanelRep;
		try {
			mapPanelRep = GameModel.getInstance().getMap().generatePanel();
			this.add(mapPanelRep);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JPanel playerInfo = new JPanel(new GridLayout(1,GameModel.getInstance().getNumPlayers()));
		for (int i = 0; i < GameModel.getInstance().getNumPlayers(); i++) {
			JPanel playerPanel = new JPanel();
			JLabel playerLabel = new JLabel("<html><center>Player Information<br/> Name: " 
					+ GameModel.getInstance().getPlayers().get(i).getName() + "<br/>Player Color: " 
					+ GameModel.getInstance().getPlayers().get(i).colorToString() + "<br/>Money: $" 
					+ GameModel.getInstance().getPlayers().get(i).getMoney() + "<br/>Food: "
					+ GameModel.getInstance().getPlayers().get(i).getPlayerResource(0) + "<br/>Energy: "
					+ GameModel.getInstance().getPlayers().get(i).getPlayerResource(1) + "<br/>Smithore: "
					+ GameModel.getInstance().getPlayers().get(i).getPlayerResource(2)
					+ "</center></html>");
			//JLabel playerName = new JLabel ("\nName: " + GameModel.getPlayers().get(i).getName());
			//playerName.setForeground(GameModel.getPlayers().get(i).getColor());
			playerPanel.add(playerLabel);
			//playerPanel.add(playerName);
			playerInfo.add(playerPanel);
		}
		this.add(playerInfo, BorderLayout.SOUTH);
	}
	
	/**
	 * Sets the text to the label at BorderLayout.NORTH of the main screen.
	 * 
	 * @param text The text the label will display
	 */
	public void setMainLabel(String text) {
		GameModel.getInstance().setLabel(text);
	}

	
}